﻿package com.eitb.botones {
	import flash.geom.*;
	import flash.text.*;
	import flash.events.*;
	import flash.display.*;
	import com.eitb.events.ScrollEvent;
	public class ScrollGaleria extends Boton {
		private var MIN_Y:Number;
		private var MAX_Y:Number;
		private var mover:Boolean;
		public function ScrollGaleria():void {
			MIN_Y = this.riel.y;
			MAX_Y = this.riel.height;
			this.addEventListener(MouseEvent.MOUSE_DOWN,downBoton);
			this.addEventListener(MouseEvent.MOUSE_UP,upBoton);
			this.addEventListener(MouseEvent.MOUSE_OUT,outBoton);			
			this.addEventListener(MouseEvent.MOUSE_MOVE, moveMouse);
			this.mover = false;
		}
		
		private function moveMouse(event:MouseEvent):void {
			if (this.mover) {
				this.boton.y = this.mouseY;
				if (this.boton.y < MIN_Y) {
					this.boton.y = MIN_Y;
				} else if (this.boton.y > MAX_Y) {
					this.boton.y = MAX_Y;
				}
				this.dispatchEvent(new ScrollEvent(ScrollEvent.POINT_SELECTED, {porcentaje:(( (this.boton.y - MIN_Y) / (MAX_Y - MIN_Y)))}));
			}
		}
		private function downBoton(event:MouseEvent):void {
			var point:Point = localToGlobal(new Point(event.currentTarget.mouseX, event.currentTarget.mouseY));
			
			if (this.boton.hitTestPoint(point.x,point.y)){
				this.mover = true;
			}
		}
		private function upBoton(event:MouseEvent):void {
			this.mover = false;
		}
		private function outBoton(event:MouseEvent):void {
			this.mover = false;
		}
	}
}